﻿using BarrageGrab;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarrageGrab
{
    public partial class GiftForm : UIForm
    {
        private string mode = "";  //添加，修改
        private Dictionary<string, string> gift;

        public GiftForm(string op,Dictionary<string,string> g)
        {
            InitializeComponent();
            mode = op;
            gift = g;
            DataTable dt_gift = DbHelperSQLite.Query("select * from live_gift order by id desc").Tables[0];
            foreach (DataRow dr in dt_gift.Rows)
            {
                cmbGift.Items.Add(dr["gift_name"].ToString());
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (mode == "添加") {
                string insertSql = $"insert into gift_config (gift_name,gift_cycle,gift_tube) values ('{cmbGift.Text}','{txtGiftCycle.Text}','{cbGiftTube.Text}')";
                DbHelperSQLite.ExecuteSql(insertSql);
            }
            else if (mode == "修改")
            {
                string updateSql = $"update gift_config set gift_name='{cmbGift.Text}', gift_cycle='{txtGiftCycle.Text}',gift_tube='{cbGiftTube.Text}' where gift_name = '{gift["gift_name"]}'";
                DbHelperSQLite.ExecuteSql(updateSql);
            }
            this.Close();

        }

        private void GiftForm_Load(object sender, EventArgs e)
        {
            if (gift != null) {
                cmbGift.Text = gift["gift_name"];
                txtGiftCycle.Text = gift["gift_cycle"];
                cbGiftTube.Text = gift["gift_tube"];
            }
        }
    }
}
